package com.itheima.health.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.SetmealDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealSrvice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class SetmealSrviceImpl implements SetmealSrvice {

    @Autowired
    private SetmealDao setmealDao;

    /**
     * 新增加套餐的添加
     * @param setmeal
     * @param checkgroupIds
     */
    @Override
    public void addAll(Setmeal setmeal, Integer[] checkgroupIds) {
         // 保存套餐基本信息
         setmealDao.insertAdd(setmeal);
         // 遍历数组保存检查项
        for (Integer checkgroupId : checkgroupIds) {
            setmealDao.insertSetmeal_Checkgroup(setmeal.getId(),checkgroupId);
        }
    }


    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        log.info("[检查项-分页查询]data：{}",queryPageBean);
        //使用分页插件
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());

        // 分页查询数据库
        Page<Setmeal> page = setmealDao.selectfindPage(queryPageBean.getQueryString());

        //封装分页数据
        return new PageResult(page.getTotal(),page.getResult());
    }
}
